package com.hl.card.common.util;

import org.web3j.utils.Convert;

import java.math.BigDecimal;

public class CurrencyUtil {
	public static String converDisString(Long amount, String currency) {
		if("cny".equals(currency)) {
				return AmountUtil.convertCent2Dollar(amount + "") + " " + "元";
		}else if("eth".equals(currency)){
			BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI);
			return Convert.fromWei(amountWEI, Convert.Unit.ETHER).doubleValue() + " " + "ETH";
		}else {
			return amount + " " + currency;
		}
	}

	public static BigDecimal converEthToGWEI(Double amount) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.ETHER);
		return Convert.fromWei(amountWEI, Convert.Unit.GWEI).setScale(0);
	}

	public static BigDecimal converGWEIToWEI(Double amount) {
		return Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI);
	}

	public static BigDecimal converGWEIToETH(Double amount) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI);
		return Convert.fromWei(amountWEI, Convert.Unit.ETHER);
	}

	public static String converEthToGWEIToStr(Double amount) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.ETHER);
		return Convert.fromWei(amountWEI, Convert.Unit.GWEI).stripTrailingZeros().toPlainString();
	}

	public static String converGWEIToWEIToStr(Double amount) {
		return Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI).stripTrailingZeros().toPlainString();
	}

	public static String converGWEIToETHToStr(Double amount) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI);
		return Convert.fromWei(amountWEI, Convert.Unit.ETHER).stripTrailingZeros().toPlainString();
	}

	public static String converEthToGWEIToStr(Double amount, int scale) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.ETHER);
		return Convert.fromWei(amountWEI, Convert.Unit.GWEI).stripTrailingZeros().toPlainString();
	}

	public static String converGWEIToWEIToStr(Double amount, int scale) {
		return Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI).stripTrailingZeros().toPlainString();
	}

	public static String converGWEIToETHToStr(Double amount, int scale) {
		BigDecimal amountWEI = Convert.toWei(BigDecimal.valueOf(amount), Convert.Unit.GWEI);
		return Convert.fromWei(amountWEI, Convert.Unit.ETHER).setScale(scale, BigDecimal.ROUND_UP).toPlainString();
	}
}